package org.springframework.data.mybatis.repository.support;

import java.io.Serializable;
import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.QueryByExampleExecutor;

@NoRepositoryBean
public interface MybatisRepository<T, ID extends Serializable> extends PagingAndSortingRepository<T, ID>, QueryByExampleExecutor<T> {

	<S extends T> S insert(S entity);

	<S extends T> S update(S entity);

	<S extends T> S updateIgnoreNull(S entity);

	<S extends T> S saveIgnoreNull(S entity);

	@Override
	<S extends T> List<S> save(Iterable<S> entities);

	<X extends T, S extends T> int updateByCondition(X condition, S update);

	<X extends T, S extends T> int updateByEqCondition(X condition, S update);

	void deleteByCondition(Iterable<T> entities);

	void deleteByEqCondition(Iterable<T> entities);

	<X extends T> int deleteByCondition(X condition);

	<X extends T> int deleteByEqCondition(X condition);

	<X extends T> Long countByCondition(X condition);

	<X extends T> Long countByEqCondition(X condition);

	<X extends T> T findOneByCondition(X condition);
	
	<X extends T> T findOneByEqCondition(X condition);

	T findOne(ID id, Long version);

	<X extends T> List<T> findAllByCondition(X condition);
	
	<X extends T> List<T> findAllByEqCondition(X condition);

	<X extends T> List<T> findAllByCondition(Sort sort, X condition);
	
	<X extends T> List<T> findAllByEqCondition(Sort sort, X condition);

	<X extends T> Page<T> findAllByCondition(Pageable pageable, X condition);
	
	<X extends T> Page<T> findAllByEqCondition(Pageable pageable, X condition);

}
